﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;
namespace DAO
{
    public class NgayVDLSDA
    {
        public static NgayVDLS GetByID(int maID)
        {
            NgayVDLS loai = null;
            SqlConnection cn = DataProvider.Connect();
            SqlCommand cmd = new SqlCommand("Proc_NgayVDLS_GetById", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@maNgayVDLS", maID));
            SqlDataReader dataReader = cmd.ExecuteReader();
            if (dataReader.Read())
            {
                loai = new NgayVDLS();
                loai.MaNgayVDLS = maID;
                loai.Ngay = Convert.ToDateTime(dataReader["Ngay"]);
                loai.LastUpdate = Convert.ToDateTime(dataReader["LastUpdate"]);
                loai.DelFlg = Convert.ToInt32(dataReader["DelFLg"]);
                loai.MaNV = Convert.ToInt32(dataReader["MaNV"]);
                 
            }
            cn.Close();
            return loai;
        }
        public static List<NgayVDLS> GetByMaNV(int maID)
        {
            List<NgayVDLS> ngay = new List<NgayVDLS>();
            NgayVDLS loai = null;
            SqlConnection cn = DataProvider.Connect();
            SqlCommand cmd = new SqlCommand("Proc_NgayVDLS_GetByMaNV", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@maNV", maID));
            SqlDataReader dataReader = cmd.ExecuteReader();
            while (dataReader.Read())
            {
                loai = new NgayVDLS();
                loai.MaNV = maID;
                loai.Ngay = Convert.ToDateTime(dataReader["Ngay"]);
                loai.LastUpdate = Convert.ToDateTime(dataReader["LastUpdate"]);
                loai.DelFlg = Convert.ToInt32(dataReader["DelFLg"]);
                loai.MaNgayVDLS = Convert.ToInt32(dataReader["MaNgayVDLS"]);
                ngay.Add(loai);
            }
            cn.Close();
            return ngay;
        }

    }
}
